package cn.bandeqing.frame.dubbo;

import cn.bandeqing.base.util.Constants;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate(group = {CommonConstants.PROVIDER}, order = -10000)
public class DubboProviderFilter implements Filter {

    public static ThreadLocal<String> APP_NAME = new ThreadLocal<>();

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        // 取出 Same-Token 进行校验
//        String sameToken = invocation.getAttachment(SaSameUtil.SAME_TOKEN);
//        SaSameUtil.checkToken(sameToken);

        // 取出其他自定义附加数据
        // TenantContext tenantContext = invocation.getAttachment("tenantContext");
        String appName = invocation.getAttachment(Constants.appName);
        APP_NAME.set(appName);

        // 开始调用
        return invoker.invoke(invocation);
    }

}
